<template>
  <BaseQuery>
    <BaseQueryLeft :span="2">
      <el-button icon="el-icon-plus" :size="formSize" type="primary" @click="edit">
        添加
      </el-button>
    </BaseQueryLeft>
    <BaseQueryRight :span="22">
      <el-form :model="form" :inline="true" :size="formSize">
        <el-form-item label="渠道:">
          <el-select v-model="form.channelId" clearable placeholder="请选择">
            <el-option v-for="item in channelList" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="媒体:">
          <el-select v-model="form.media" clearable placeholder="请选择">
            <el-option v-for="item in mediaList" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="城市:">
          <el-select v-model="form.city" clearable placeholder="请选择">
            <el-option v-for="item in cityList" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
        </el-form-item>
      </el-form>
    </BaseQueryRight>
  </BaseQuery>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "QueryForm",
  props: {
    value: {
      type: Object,
      default: () => {},
    },
    mediaList: {
      type: Array,
      default: () => [],
    },
    channelList: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      form: {},
      formSize: "small",
    };
  },
  computed: {
    ...mapState("app", ["cityList"]),
  },
  watch: {
    value: {
      handler(val) {
        this.form = val;
      },
      deep: true,
      immediate: true,
    },
    form: {
      handler(val) {
        console.log(val);
        this.$emit("input", val);
      },
      deep: true,
    },
  },
  methods: {
    search() {
      this.$parent.page.page = 1;
      this.$emit("search");
    },
    edit() {
      this.$router.push({ name: "rationCreate", params: { type: "add" } });
    },
  },
};
</script>
